home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / e / megsplit.c < prev    next >
C/C++ Source or Header  |  1993-07-09  |  507b  |  33 lines

  1. #include <sys/types.h>
  2. #include <sys/stat.h>
  3. #include <fcntl.h>
  4.  
  5. /* spit a file (stdin) into 2meg chunks */
  6. #define twomeg (2*1024*1024)
  7. char rbuf[twomeg];
  8. main(int argc, char *argv[])
  9. {
  10.     int rcount;
  11.     int nreads = 0;
  12.     char f2name[100]; 
  13.     int fd2;
  14.     while ((rcount = read(0,rbuf,twomeg))>0)
  15.     {
  16.         sprintf(f2name,"%s.%d",argv[1],nreads);
  17.         fd2 = creat(f2name,0644);
  18.         if (write(fd2,rbuf,rcount)<rcount)
  19.         {
  20.             perror("write failed");
  21.             exit();
  22.         }
  23.         nreads++;
  24.     }
  25.     if (rcount<0)
  26.         perror("read failed");
  27. }
  28.  
  29.  
  30.  
  31.  
  32.  
  33.